{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-06-13T10:50:54.592505400Z",
     "start_time": "2023-06-13T10:50:54.577334100Z"
    }
   },
   "outputs": [],
   "source": [
    "import func\n",
    "import warnings\n",
    "\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "\n",
    "FILE_PATH = \"../dataset/satisfaction_v2.csv\"\n",
    "PICTURE_PATH = \"../picture/\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "#数据集读取与分离\n",
    "data = func.get_pre_processed_data_set(FILE_PATH)\n",
    "data_x, data_y = func.x_y_split(data, \"satisfaction_v2\")\n",
    "train_data, test_data, dev_data = func.split_data(data)\n",
    "train_x, train_y = func.x_y_split(train_data, \"satisfaction_v2\")\n",
    "test_x, test_y = func.x_y_split(test_data, \"satisfaction_v2\")\n",
    "dev_x, dev_y = func.x_y_split(dev_data, \"satisfaction_v2\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-06-13T10:50:55.032836Z",
     "start_time": "2023-06-13T10:50:54.596467700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "test_acc:0.6830643292918372,dev_acc:0.7039925863001004\n",
      "test_acc:0.6728704919298788,dev_acc:0.6852266584292224\n",
      "test_acc:0.702834195690787,dev_acc:0.7151131361495097\n",
      "test_acc:0.6958066259942852,dev_acc:0.7067727237624527\n",
      "test_acc:0.705768785234381,dev_acc:0.7154220403119932\n",
      "test_acc:0.7017530311220944,dev_acc:0.7157309444744768\n",
      "test_acc:0.705768785234381,dev_acc:0.7184338558962082\n",
      "test_acc:0.7087033747779752,dev_acc:0.7166576569619275\n",
      "test_acc:0.7100934435091513,dev_acc:0.719283342343038\n",
      "test_acc:0.7097845393466677,dev_acc:0.7175071434087574\n",
      "test_acc:0.7072360800061781,dev_acc:0.7152675882307514\n",
      "test_acc:0.7066954977218318,dev_acc:0.717043787165032\n",
      "test_acc:0.7070816279249363,dev_acc:0.7106340257934975\n",
      "test_acc:0.7090895049810796,dev_acc:0.7117151903621901\n",
      "test_acc:0.7055371071125184,dev_acc:0.7069271758436945\n",
      "test_acc:0.7089350528998378,dev_acc:0.7093211831029423\n",
      "test_acc:0.705073750868793,dev_acc:0.7047648467063093\n",
      "test_acc:0.7066182716812109,dev_acc:0.7067727237624527\n",
      "test_acc:0.7047648467063093,dev_acc:0.7042242644219631\n",
      "max_dev_acc:0.719283342343038,max_test_acc:0.7100934435091513,max_dev_arg=9\n"
     ]
    }
   ],
   "source": [
    "max_dev_acc=0\n",
    "max_test_acc=0\n",
    "max_dev_arg=0\n",
    "for i in range(1,20):\n",
    "    test_acc,dev_acc=func.k_neighbors(train_x, train_y,test_x, test_y,dev_x, dev_y,n_neighbors=i)\n",
    "    print(f\"k={i},test_acc:{test_acc},dev_acc:{dev_acc}\")\n",
    "    if dev_acc>max_dev_acc:\n",
    "        max_dev_acc=dev_acc\n",
    "        max_test_acc=test_acc\n",
    "        max_dev_arg=i\n",
    "print(f\"max_dev_acc:{max_dev_acc},max_test_acc:{max_test_acc},max_dev_arg(k)={max_dev_arg}\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-06-13T10:51:52.525447800Z",
     "start_time": "2023-06-13T10:50:55.035325800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "test_acc:0.9653255077612171,dev_acc:0.9595335547146497\n",
      "test_acc:0.9649393775581125,dev_acc:0.9613097536489305\n",
      "test_acc:0.9651710556799753,dev_acc:0.9605374932427214\n",
      "test_acc:0.9647849254768708,dev_acc:0.9612325276083096\n",
      "test_acc:0.964630473395629,dev_acc:0.9614642057301722\n",
      "test_acc:0.9648621515174917,dev_acc:0.960846397405205\n",
      "test_acc:0.9655571858830798,dev_acc:0.9604602672021005\n",
      "test_acc:0.9652482817205962,dev_acc:0.9619275619738976\n",
      "test_acc:0.9653255077612171,dev_acc:0.9611553015676886\n",
      "test_acc:0.9660977681674261,dev_acc:0.9614642057301722\n",
      "test_acc:0.9649393775581125,dev_acc:0.9616958838520349\n",
      "test_acc:0.9655571858830798,dev_acc:0.9620820140551394\n",
      "test_acc:0.9659433160861842,dev_acc:0.9613097536489305\n",
      "test_acc:0.9650166035987335,dev_acc:0.9621592400957603\n",
      "test_acc:0.9655571858830798,dev_acc:0.9617731098926559\n",
      "test_acc:0.9659433160861842,dev_acc:0.9617731098926559\n",
      "max_dev_acc:0.9621592400957603,max_test_acc:0.9650166035987335,max_dev_arg=425\n"
     ]
    }
   ],
   "source": [
    "max_dev_acc=0\n",
    "max_test_acc=0\n",
    "max_dev_arg=0\n",
    "for i in range(100,500,25):\n",
    "    test_acc,dev_acc=func.random_forest(train_x, train_y,test_x, test_y,dev_x, dev_y,n_estimators=i)\n",
    "    print(f\"k={i},test_acc:{test_acc},dev_acc:{dev_acc}\")\n",
    "    if dev_acc>max_dev_acc:\n",
    "        max_dev_acc=dev_acc\n",
    "        max_test_acc=test_acc\n",
    "        max_dev_arg=i\n",
    "print(f\"max_dev_acc:{max_dev_acc},max_test_acc:{max_test_acc},max_dev_arg(k)={max_dev_arg}\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-06-13T11:00:08.379710Z",
     "start_time": "2023-06-13T10:51:52.527874800Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
